<template>
  <div class="home-banner">
    <el-carousel height="500px">
      <el-carousel-item v-for="item in bannerList" :key="item.id">
        <img :src="item.imgUrl" alt="" />
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup lang="ts">
import { defineOptions, ref, onMounted } from "vue";
// 引入API
import { reqGetBannerList } from "@/apis/home";
defineOptions({
  name: "HomeBanner",
});
let bannerList = ref([]); //存储轮播图数据的数组
onMounted(() => {
  getBannerList();
});
//获取已有轮播图数据
const getBannerList = async () => {
  let result: any = await reqGetBannerList();
  bannerList.value = result.result;
};
</script>

<style scoped lang="scss">
.home-banner {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 98;
  width: 1240px;
  height: 500px;
  background-color: palegoldenrod;
  img {
    width: 100%;
    height: 500px;
  }
}
</style>
